package com.vvlive.caibao.smartcity.base;

import com.vvlive.caibao.smartcity.utils.GsonUtil;

import org.kymjs.kjframe.http.HttpCallBack;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.ParameterizedType;
import java.util.List;

/**
 * Created by zhj on 2015/9/9.
 */
public abstract class ListHttpCallBack<T> extends HttpCallBack {

    public static final String GBK = "GBK";

    @Override
    public void onSuccess(byte[] t) {
        try {

            onSuccess(GsonUtil.toList(new String(t, GBK), getType()));

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onFailure(int errorNo, String strMsg) {
        onError(errorNo, strMsg);
    }

    private Class<T> getType(){
        return (Class<T>)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    }

    public abstract void onSuccess(List<T> list);

    public abstract void onError(int errCode, String str);
}
